const Service = require("uni-cloud-router").Service;
// 必须继承 Service
module.exports = class RadioService extends Service {
  async getSleepType() {
	const data = this.ctx.data // 从 Context 实例上获取请求参数
	console.log("客户端上传的参数:",data);
  	// 查询数据表
  	let response = await this.db.collection('ratio_story_types').get()
  	//返回数据给客户端
  	return {
  		code: 200,
  		message: "数据请求成功",
  		data: response.data
  	}
  };
  
  async getStoryListWithType() {
	  const data = this.ctx.data // 从 Context 实例上获取请求参数
	  console.log("客户端上传的参数:",data);
	  // 查询数据表
	  let response = await this.db.collection('ratio_story_list').orderBy('register_date','desc').get()
	  //返回数据给客户端
	  return {
	  	code: 200,
	  	message: "数据请求成功",
	  	data: response.data
	  }
  };
  
  /* 根据类型和页码分页 */
  async getStoryListWithModelData() {
	  const data = this.ctx.data // 从 Context 实例上获取请求参数
	  const type = data.type;
	  const page = data.page;
	  const number = 10;
	  // 查询数据表
	  let response = await this.db.collection('ratio_story_list')
									.orderBy('register_date','desc')
									.skip(page * number)
									.limit(number)
									.get()
	  //返回数据给客户端
	  return {
	  	code: 200,
	  	message: "数据请求成功",
	  	data: response.data
	  }
  };
  
  
};